/*
 * Copyright (C) 2009 Kristopher T Babic
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see <http://www.gnu.org/licenses>.
 */

package edu.idp.client.anim;

import java.awt.*;

/**
 *
 * @author Kristopher T Babic
 */
public class LinePath extends AnimationPath {

    private Point moveVector = null;
    static private final Point _defaultLineVector = new Point(0, 0);

    public LinePath() {
        super();
        setMoveVector(_defaultLineVector);
    }

    public LinePath(Point origin) {
        super(origin);
        setMoveVector(_defaultLineVector);
    }

    public LinePath(Point origin, Point move) {
        super(origin);
        setMoveVector(move);
//System.out.println("setting origin to: "+origin);
    }

    public Point getLocation() {
        long cycles = getCycles();
        Point dir = getMoveVector();
        Point orig = getStartLocation();

//    Rectangle bounds = getBounds();
        int x = orig.x + (int) ((long) dir.x * cycles);
        int y = orig.y + (int) ((long) dir.y * cycles);

        Point location = getReflectedLocation(x, y);
//System.out.println(getTime()+" - "+getStartTime()+" / "+getDeltaMove()+" = "+cycles);
        //System.out.println(dir+" -> "+(long)dir.x+","+(long)dir.y+"  --  "+cycles);
        //System.out.println(getStartLocation()+" new loc: "+location);
        return location;

        //return getReflectedLocation (x, y);

////    if (bounds == null) {
////      return new Point (x, y);
/*
                        orig.x + (int)((long)dir.x * cycles),
                        orig.y + (int)((long)dir.y * cycles));
 */
////    }
////    else {
//      boolean mod = false;
////      x = x % bounds.width;
////      y = y % bounds.height;
////
////      if (x < 0)
////        x = bounds.width + x; //- x;
////      if (y < 0)
////        y = bounds.height + y; //- y;
////
////      Point location = new Point (x, y);

/*
      if (x > bounds.width) {
        mod = true;
        x = 0;
      }
      else if (x < 0) {
        mod = true;
        x = bounds.width;
      }
      if (y > bound.height) {
        mod = true;
        y = 0;
      }
      else if (y < 0) {
        mod = true;
        y = bounds.height;
      }

      Point location = new Point(x, y);
      if (mod)
        setLocation(location);
*/
////      return location;

/*
      return new Point ((orig.x + (int)((long)dir.x * cycles)) / bounds.width,
                        (orig.y + (int)((long)dir.y * cycles)) / bounds.height);
 */
////    }

    }

    //  public void setLocation ( int x, int y) { setLocation (new Point(x, y)); }
    public void setLocation(Point loc) {
        System.out.println("set Location has been called with " + loc);
        setStartLocation(loc);
        setStartTime();
    }

    public Point getMoveVector() {
        return this.moveVector;
    }

    public void setMoveVector(Point move) {
        this.moveVector = move;
    }

    public String toString() {
        return "Line Path -\nLine Vector: (" + getMoveVector().x + "," + getMoveVector().y + ")";
    }
}